package cn.school.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public abstract class BaseTreeNode {
    private Long id;
    /**
     * 父ID
     * */
    private Long  pid;
    /**
     * 节点名称
     * */
    private String label;

    private Boolean isDefaultExpanded = false;

    private Boolean isDisabled = false;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<BaseTreeNode> children;

    public void init(Long id, Long pid, String levelName) {
        this.id = id;
        this.pid = pid;
        this.label = levelName;
    }

    public void addChildren(BaseTreeNode childrenNode) {
        if (this.children == null) {
            children = new ArrayList<>();
        }
        children.add(childrenNode);
    }


}
